package com.asset.dispoal.business.bsAgreement.domain.db.mapper;

import com.asset.dispoal.business.bsAgreement.domain.db.entity.Agreement;
import com.asset.dispoal.business.bsAgreement.domain.db.entity.AgreementCase;
import com.asset.dispoal.business.bsAgreement.domain.db.entity.AgreementCaseState;
import com.asset.dispoal.business.bsAgreement.domain.db.entity.AgreementExpand;
import com.asset.dispoal.business.bsAgreement.domain.db.entity.AgreementInfo;
import com.asset.dispoal.business.bsAgreement.domain.db.entity.AgreementStateRecord;
import com.asset.dispoal.business.bsAgreement.domain.db.entity.SingleAgreementCaseState;
import com.asset.dispoal.business.bsAgreement.dto.AgreementDataRequest;
import com.asset.dispoal.business.bsAgreement.dto.AgreementDataResponse;
import com.asset.dispoal.business.bsAgreement.dto.AgreementResponse;
import com.asset.dispoal.business.bsAgreement.dto.StateRecordResponse;
import com.asset.dispoal.business.reportAnalysis.dto.HomeMonthResponse;
import com.asset.dispoal.business.reportAnalysis.dto.HomeNumberResponse;
import com.asset.dispoal.business.reportAnalysis.dto.StatisticsAgencyAgreeInfo;
import com.asset.dispoal.business.reportAnalysis.dto.StatisticsKindAgreeInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import tech.mhuang.pacebox.springboot.core.mapper.BaseMapper;
import tech.mhuang.pacebox.springboot.protocol.data.Page;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author qr
 * @date 2022/4/7$
 */
@Mapper
public interface AgreementMapper extends BaseMapper<Agreement, String> {

    /**
     * 批量保存合同
     *
     * @param agreementList
     */
    void batchSaveAgreement(@Param("agreementList") List<Agreement> agreementList);

    /**
     * 批量保存
     *
     * @param agreementExpands
     */
    void batchSaveAgreementExpand(@Param("agreementExpands") List<AgreementExpand> agreementExpands);

    /**
     * 批量保存合同案件关联
     *
     * @param agreementCases
     */
    void batchSaveAgreementCase(@Param("agreementCases") List<AgreementCase> agreementCases);

    void deleteAgreementCaseByAgreementIds(@Param("agreementIds") List<String> agreementIds);

    List<Agreement> queryAgreementByByIdCardAndBatchId(@Param("assetInstBatchId") String assetInstBatchId, @Param("idcardList") List<String> idcardList);

    /**
     * 查询合同
     *
     * @param request
     * @return
     */
    List<Agreement> queryAgreement(@Param("request") Agreement request);


    AgreementDataResponse queryAgreementData(@Param("id") String id);

    /**
     * 修改合同信息
     *
     * @param agreement
     */
    void updateAgreement(@Param("item") Agreement agreement);

    /**
     * 修改合同扩展信息
     *
     * @param agreementExpand
     */
    void updateAgreementExpand(@Param("item") AgreementExpand agreementExpand);


    int queryAgreementsCount(@Param("request") AgreementDataRequest request);

    List<AgreementDataResponse> queryAgreementDatas(@Param("request") Page<AgreementDataRequest> page);

    void batchOptAgreementExpand(@Param("agreementExpands") List<AgreementExpand> agreementExpandUptDtoList);

    void batchOptAgreement(@Param("agreementList") List<Agreement> agreementUptDtoList);

    Integer insertStateRecord(AgreementStateRecord agreementStateRecord);

    void updateAgreementState(@Param("agreementId") String agreementId, @Param("state") String waitDeliver, @Param("userId") String userId);

    List<String> queryAgreementByNo(@Param("contractNoList") List<String> contractNoStrList, @Param("assetInstBatchId") String assetInstBatchId);

    void batchSaveAgreementRecord(@Param("recordList") List<AgreementStateRecord> agreementStateRecordList);

    List<StateRecordResponse> queryStateRecordById(@Param("id") String id);

    List<AgreementCaseState> queryAgreementCaseStateByAgreementId(@Param("agreementId") String agreementId);

    Integer updateCaseState(@Param("id") String id, @Param("state") String state, @Param("complateState") String complateState, @Param("userId") String userId);

    Integer updateCaseStateAndReason(@Param("id") String id,
                                     @Param("state") String state,
                                     @Param("complateState") String complateState,
                                     @Param("userId") String userId,
                                     @Param("wasteReasonId") String wasteReasonId);

    SingleAgreementCaseState querySingleAgreementCaseStateByAgreementId(@Param("agreementId") String id);

    List<AgreementResponse> queryAgreementDataList(@Param("idList") List<String> idList, @Param("permission") String permission);

    String getCaseIdByContractIdCard(@Param("assetInstBatchId") String assetInstBatchId, @Param("contractNo") String contractNo, @Param("idCard") String idCard);

    List<AgreementCaseState> queryAgreementCaseStateByCaseId(String id);

    /**
     * 根据案件id查询合同金钱,逾期信息
     *
     * @param caseId
     * @return
     */
    List<AgreementInfo> queryAgreementInfoByCaseId(String caseId);

    /**
     * 获取默认废案原因
     *
     * @return
     */
    String getDefaultAbolishedReasonId();

    List<String> queryAgreementIdByCaseIds(@Param("caseIdList") List<String> caseIdList);

    /**
     * 查询合同总数量
     *
     * @return
     */
    Integer getAgreeNums();

    /**
     * 本周新增合同数量
     *
     * @return
     */
    Integer getThisWeekNewAgreeNums();

    /**
     * 可派送的合同数量
     *
     * @return
     */
    Integer getSentAgreeNums();

    /**
     * 本周可派合同数量
     *
     * @return
     */
    Integer getThisWeekSentAgreeNums();

    /**
     * 不可派合同数量
     *
     * @return
     */
    Integer getNotSentAgreeNums();

    /**
     * 本周不可派合同数量
     *
     * @return
     */
    Integer getThisWeekNotSentAgreeNums();

    /**
     * 机构统计合同列表
     *
     * @return
     */
    List<StatisticsAgencyAgreeInfo> getContractAgencyStatistics();

    /**
     * 种类统计合同列表
     *
     * @return
     */
    List<StatisticsKindAgreeInfo> getContractKindStatistics();

    Integer checkInstBatch(@Param("id") String assetInstBatchId);

    List<Map<String, String>> queryMapByAssetInstIdAndCheckAddress(@Param("assetInstBatchId") String assetInstBatchId);

    void updateAddressProcessStateByInstBatchId(@Param("assetInstBatchId") String assetInstBatchId);

    HomeNumberResponse queryContractNum(@Param("startDay") Date currentStartDay, @Param("endDay") Date currentEndDay,
                                        @Param("startWeek") Date currentStartWeek, @Param("endWeek") Date currentEndWeek,
                                        @Param("startMonth") Date currentStartMonth, @Param("endMonth") Date currentEndMonth,
                                        @Param("startYear") Date currentStartYear, @Param("endYear") Date currentEndYear);

    HomeNumberResponse queryCaseNum(@Param("startDay") Date currentStartDay, @Param("endDay") Date currentEndDay,
                                    @Param("startWeek") Date currentStartWeek, @Param("endWeek") Date currentEndWeek,
                                    @Param("startMonth") Date currentStartMonth, @Param("endMonth") Date currentEndMonth,
                                    @Param("startYear") Date currentStartYear, @Param("endYear") Date currentEndYear);

    HomeNumberResponse queryLawyerNum(@Param("startDay") Date currentStartDay, @Param("endDay") Date currentEndDay,
                                      @Param("startWeek") Date currentStartWeek, @Param("endWeek") Date currentEndWeek,
                                      @Param("startMonth") Date currentStartMonth, @Param("endMonth") Date currentEndMonth,
                                      @Param("startYear") Date currentStartYear, @Param("endYear") Date currentEndYear);

    HomeNumberResponse queryEvidenceNum(@Param("startDay") Date currentStartDay, @Param("endDay") Date currentEndDay,
                                        @Param("startWeek") Date currentStartWeek, @Param("endWeek") Date currentEndWeek,
                                        @Param("startMonth") Date currentStartMonth, @Param("endMonth") Date currentEndMonth,
                                        @Param("startYear") Date currentStartYear, @Param("endYear") Date currentEndYear);

    List<HomeMonthResponse> queryContractMonth(@Param("startYear") Date currentStartYear);

    List<HomeMonthResponse> queryCaseMonth(@Param("startYear") Date currentStartYear);

    List<HomeMonthResponse> queryLawyerMonth(@Param("startYear") Date currentStartYear);

    List<HomeMonthResponse> queryEvidenceMonth(@Param("startYear") Date currentStartYear);

    String getOldStateByContractId(String id);
}
